import xlwings as xw
import win32com.client as win32


def encrypt_excel_win32(file_path: str, password: str):
    print(f'文件地址：{file_path},密码：{password}')
    excel = win32.gencache.EnsureDispatch('Excel.Application')
    workbook = excel.Workbooks.Open(file_path)
    # Set a password for the workbook
    workbook.Password = password

    # Save and close the workbook
    workbook.Save()
    workbook.Close()
    print(f'{file_path}:加密完成1')


def encrypt_excel_xlw(file_path: str, password: str):
    print(f'文件地址：{file_path},密码：{password}')
    xlw = xw.Book()
    xlw.api.SaveAs(file_path, password, password)
    xlw.close()
    print(f'{file_path}:加密完成2')


# encrypt_excel_win32(r'D:\Users\12717\Downloads\python\code\1.xlsx', '123456')
# encrypt_excel_xlw(r'D:\Users\12717\Downloads\python\code\2.xlsx', '654321')
